home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1995, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /*
- * stars.c
- *
- * functions to initialize and draw a bunch of stars
- *
- * init_stars() code courtesy of David Marsland.
- *
- * Copyright 1993, Silicon Graphics, Inc.
- * All Rights Reserved.
- */
- #include <stdlib.h>
- #include <GL/gl.h>
- #include "stars.h"
-
- /* init_stars()
- * init_stars() initializes array of MAXSTARS stars in 3-D
- */
-
- #define MAXSTARS 1000 /* number of stars */
-
- static float starcol[MAXSTARS][4];
- static float star[MAXSTARS][3];
-
- void init_stars(void)
- {
- int j, k;
-
- for (j = 0; j < MAXSTARS ; j++)
- {
- for (k = 0; k < 3; k++)
- {
- /* x,y,z */
- star[j][k] = (GLfloat) rand()/(GLfloat) RAND_MAX - 0.5;
-
- }
- starcol[j][0] = starcol[j][1] = starcol[j][2] = starcol[j][3] =
- 0.3 + 0.7 * rand()/(GLfloat)RAND_MAX;
- starcol[j][3] = 1.0;
- }
- }
-
- /* draw_stars()
- * draw_stars() draws MAXSTARS stars in 3-D
- */
- void draw_stars( GLfloat distance )
- {
- int i;
-
- glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_POINT_BIT );
- glDisable( GL_DEPTH_TEST );
- glPointSize( 2.5 );
-
- glPushMatrix();
- glScalef( distance, distance, distance );
- glBegin(GL_POINTS);
- for(i = 0; i < MAXSTARS; i++)
- {
- glColor4fv(&starcol[i][0]);
- glVertex3fv(&star[i][0]); /* x,y,z */
- }
- glEnd();
- glPopMatrix();
-
- glPopAttrib();
- }
-